using System;
using System.Collections.Generic;
using System.Text;
using LeisureCenter.Api;

namespace LeisureCenter.Core
{
    public class PlayersManager : IPlayersManager
    {
        private Dictionary<string, IPlayer> players = new Dictionary<string,IPlayer>(StringComparer.InvariantCultureIgnoreCase);
        private IPlayer audioCdPlayer;
        private IPlayer videoDvdPlayer;

        #region IPlayersManager Membres

        public void RegisterPlayer(string name, IPlayer player)
        {
            players.Add(name, player);

            Attribute attribute = Attribute.GetCustomAttribute(player.GetType(), typeof(AudioCdPlayerAttribute));
            if (attribute != null)
                this.audioCdPlayer = player;
            attribute = Attribute.GetCustomAttribute(player.GetType(), typeof(VideoDvdPlayerAttribute));
            if (attribute != null)
                this.videoDvdPlayer = player;
        }

        public void UnRegisterPlayer(string name)
        {
            players.Remove(name);
        }

        public IPlayer this[string name]
        {
            get
            {
                IPlayer player;
                players.TryGetValue(name, out player);
                return player;
            }
        }

        public IPlayer AudioCdPlayer { get { return this.audioCdPlayer; } }
        public IPlayer VideoDvdPlayer { get { return this.videoDvdPlayer; } }

        #endregion
    }
}
